<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONArray"%>
<%@page contentType="text/html;charset=UTF-8" %>
<%@page import="service.BOService"%>
<%@page import="service.ORMService"%>
<%@page import="tools.*" %>
<%@page import="bo.*" %>
<%@page import="java.text.*" %>
<%@page import="java.util.*" %> 


<%

	request.setCharacterEncoding("utf-8");
	String action = request.getParameter("ACTION");
	ORMService ormService = ORMService.getInstance();
	BOService boService = BOService.getInstance();
	if(action.equals("addSchedule")) {
		String id = DepUtil.createPrimaryId();
		String content = request.getParameter("CONTENT");
		String date = request.getParameter("DATE");
		BusinessObject bo = boService.createBusinessObject("Schedule");
		bo.put("ID", id);
		bo.put("CONTENT", content);
		bo.put("DATE", date);
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		bo.put("CREATE_TIME", format.format(new Date()));
		ormService.insert(bo);
		String sql = "select * from T_BLOG_SCHEDULE where ID = '" + id + "'";
		bo = ormService.get(sql, bo);
		response.getWriter().write(bo.getJsonString());
	} else if(action.equals("searchSchedules")) {
		String sql = "select * from T_BLOG_SCHEDULE";
		List<BusinessObject> scheduleList = ormService.list(sql);
		JSONArray jsonArr = new JSONArray();
		for(int i = 0; i < scheduleList.size(); i++) {
			jsonArr.add(JSONObject.fromObject(scheduleList.get(i).getJsonString()));
		}
		response.getWriter().write(jsonArr.toString());
	} else if(action.equals("editSchedule")) {
		String flag = "";
		try {
			String scheduleId = request.getParameter("ID");
			String content = request.getParameter("CONTENT");
			BusinessObject bo = boService.createBusinessObject("Schedule");
			String sql = "select * from T_BLOG_SCHEDULE where ID = '" + scheduleId + "'";
			bo = ormService.get(sql, bo);
			bo.put("CONTENT", content);
			ormService.update(bo);
			flag = "{\"FLAG\":\"1\"}";
		} catch(Exception e) {
			e.printStackTrace();
			flag = "{\"FLAG\":\"0\"}";
		}
		response.getWriter().write(flag);
	}
%>